package com.example.neusoft215gdh.android_21.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.neusoft215gdh.android_21.Bean.StringBean;
import com.example.neusoft215gdh.android_21.Model.RegisterModel;
import com.example.neusoft215gdh.android_21.R;
import com.example.neusoft215gdh.android_21.Util.Common.utilMeth;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class RegisterActivity extends AppCompatActivity implements utilMeth {
    public Button btn_register;
    public EditText phoneNumber;
    public EditText passWord;
    String phone;
    String pwd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register);
        initViews();
        inEvents();
    }

    @Override
    public void initViews() {
        btn_register = (Button) findViewById(R.id.btn_register);
        phoneNumber = (EditText) findViewById(R.id.phoneNumber);
        passWord = (EditText) findViewById(R.id.pwd);
    }

    @Override
    public void inEvents() {
        btn_register.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                phone = phoneNumber.getText().toString();
                pwd = passWord.getText().toString();
                RegisterModel registerModel = new RegisterModel();

                Call call = registerModel.Register(phone, pwd);
                Toast.makeText(RegisterActivity.this, "call的值为:"+call, Toast.LENGTH_SHORT).show();

                Callback<StringBean> callback = new Callback<StringBean>() {
                    @Override
                    public void onResponse(Call<StringBean> call, Response<StringBean> response) {
                        StringBean value= response.body();
                        Toast.makeText(RegisterActivity.this, "value中的error的值为:"+value.getError(), Toast.LENGTH_SHORT).show();
//                        Toast.makeText(RegisterActivity.this, "value的值为:"+value, Toast.LENGTH_SHORT).show();
                        if(value.getError().equals("手机号已被使用")==false){
                            Toast.makeText(RegisterActivity.this, "注册成功!", Toast.LENGTH_SHORT).show();
                        }
                    }
                    @Override
                    public void onFailure(Call<StringBean> call, Throwable t) {
                        Toast.makeText(RegisterActivity.this, "注册失败!", Toast.LENGTH_SHORT).show();
                    }
                };
                call.enqueue(callback);
            }
        });
    }
}
